<%--
  Created by IntelliJ IDEA.
  User: 19416
  Date: 2022-08-17
  Time: 8:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <script src="JS/jquery-2.1.1.min.js"></script>

</head>
<body>
<%--<%--%>
<%--if (request.getAttribute("status") == null){--%>
<%--    response.sendRedirect("ListServlet");--%>
<%--}--%>
<%--%>--%>
<button onclick="add()">新增信息</button>
<table border="1px">
    <tr>
        <td>组织机构名称</td>
        <td>负责人</td>
        <td>业务状态</td>
        <td>创建日期</td>
        <td>操作</td>
    </tr>
    <c:forEach items="${requestScope.list}" var="orgnazition">
        <tr>
            <td>${orgnazition.name}</td>
            <td>${orgnazition.principalName}</td>
            <td >${orgnazition.status == 0?"开启业务":"暂停业务"}</td>
            <td>${orgnazition.createDate}</td>
            <td>
                <a href="#" onclick="up(${orgnazition.status},${orgnazition.id})">${orgnazition.status == 0?"暂停业务":"开启业务"}</a>
            </td>
        </tr>
    </c:forEach>
</table>
<span id="span2"></span>
<script>
    function add(){
        location.href="add.jsp";
    }
    function up(status,id){

        var status1 = "暂停业务";
        if (status == 1){
            status1="开启业务";
        }

            if(confirm("确定要"+status1+"吗？")){
                $.get("UpdateServlet",{"status":status,"id":id},function (data){
                    if (data>0){
                        $("#span2").html(status1+"成功")
                        location.reload();
                    }else {
                        alert("修改失败")
                        return false;
                    }

                })
            }




    }
</script>
</body>
</html>
